home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8456 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  46 lines

  1. Path: news.uni-stuttgart.de!news
  2. From: Markus Heller <Markus.Heller@studbox.uni-stuttgart.de>
  3. Newsgroups: comp.lang.c
  4. Subject: Combine zero-offset with unit-offset arrays ?
  5. Date: 4 Mar 1996 13:42:41 GMT
  6. Organization: Comp.Center (RUS), U of Stuttgart, FRG
  7. Message-ID: <4hes0h$52qi@info4.rus.uni-stuttgart.de>
  8. NNTP-Posting-Host: rusxppp168.rus.uni-stuttgart.de
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.12 (X11; I; Linux 1.2.13 i486)
  13. X-URL: news://news/comp.lang.c
  14.  
  15. Hi,
  16.  
  17. I want to combine my code (using zero-offset arrays) with
  18. code using unit-offset arrays.
  19. The FAQ - 2.16 mentions a method used "in old editions of
  20. Numerical Recipes in C" that leads to undefined behavior.
  21. Unfortunately there's no alternative mentioned.
  22. E.g.:
  23.  
  24. void somefunction( float fa[], int n);
  25.  
  26. int main(void)
  27. {
  28.  float a[10];  /* zero offset: a[0] .. a[9] */
  29.  int n=10;
  30.  
  31.  somefunction( a-1, 10 ); /* method suggested by Numerical Recipes,
  32.                              2nd edition */
  33. }                               
  34.  
  35. void somefunction( float fa[], int n)
  36. {
  37.  /* do something with a, assuming unit-offset: a[1]..a[10] */
  38. }
  39.  
  40.  
  41. Which alternatives are possible to the above mentioned method ?
  42. (Is the method still leasding to undefined behavior ?)
  43.  
  44. Markus
  45.  
  46.